let user = ''
let userInfo = ''
let openid = ''
let nickName = ''
let tx = ''
const app = getApp()
let myopenid = ''
let isLogin = ''
const db = wx.cloud.database()
Page({
    data: {
        Icons: [{
                url: "/images/地址.png",
                text: "我的地址"
            },
            {
                url: "/images/订单.png",
                text: "订单历史"
            }, {
                url: "/images/押金.png",
                text: "我的押金"
            },
        ],
        Img: [{
                url: "/images/骑手配送.png",
                text: "认证骑手"
            },
            {
                url: "/images/个人中心.png",
                text: "个人中心"
            }, {
                url: "/images/水.png",
                text: "联系客服"
            }
        ],
        VIP: [{
                url: "/images/超级VIP.png",
                text: "开发者"
            },
            {
                url: "/images/VIP.png",
                text: "管理员"
            }, {
                url: "/images/用户.png",
                text: "信息库"
            }
        ],
        userInfo: '',
        hasUserInfo: false,
        canIUseGetUserProfile: false,
    },
    onShow() {
        this.isLogin()
        console.log('初始化我的页面数据',this.data);
    },
    async isLogin(){
        await db.collection('userInfo').where({
            _openid: '{openid}',
        })
        .get()
        .then((res)=>{
            this.setData({
                userInfo: res.data,
            })
        })
        if (this.data.userInfo.length&&this.data.userInfo[0].isLogin) {
            const [userInfo] = this.data.userInfo
            this.setData({
                nickName: userInfo.nickName,
                avatarUrl: userInfo.avatarUrl,
                isLogin: true,
                isManager: userInfo.isManager,
                prompt_opacity: "0",
            })
            wx.setStorageSync('userInfo', userInfo)
        } else { //跳转至登录页面
            // wx.navigateTo({
            //   url: '../login/index',
            // })

            // this.login()
            this.setData({ isLogin: false })
        }
    },
    loginBtn() {
        wx.navigateTo({
            url: '/pages/my/login/index',
        })
    },
    address(e) {
        wx.navigateTo({
            url: '/pages/my/Address/index',
        })
    },
    goWeather() {
        wx.navigateTo({
            url: '/pages/my/weather/index',
        })
    },
    goZP() {
        wx.navigateTo({
            url: '/pages/my/know/index',
        })
    },
    goTBB() {
        wx.navigateTo({
            url: '/pages/my/xz/index',
        })
    }
})